#include "stdio.h"
#include "unistd.h"
#include "time.h"
#include "camellia.h"

int camGetTimeMs()
{
    int t;
    struct timeval tv;
    gettimeofday(&tv,NULL);
    t=tv.tv_sec*1000+tv.tv_usec/1000;
    return t;
}

// takes two args, first one is input file, second argument is output file
int main(int args, char **argv)
{
    CamImage source,dest;
    CamMorphoMathsKernel mm_params;
    int x,y;
    int t1,t2;
		int CircleStructElt[5][5]=
	   {{0,1,1,1,0},
	    {1,1,1,1,1},
	    {1,1,1,1,1},
	    {1,1,1,1,1},
	    {0,1,1,1,0}};

    camLoadPGM(&source, argv[1]);
    camAllocateImage(&dest,source.width,source.height,source.depth);
    
  	for (x=0;x<5;x++) {
			for (y=0;y<5;y++) {
			    mm_params.dilationStructElt[x][y]=CircleStructElt[x][y];
			    mm_params.erosionStructElt[x][y]=CircleStructElt[x][y];;
			}
  	 }

    mm_params.operation=CAM_MM_SUBSTRACTION;
    mm_params.source1=CAM_MM_DILATED;
    mm_params.source2=CAM_MM_ERODED;
   	t1=camGetTimeMs();
	int i;
	for(i=0; i<100; i++)
		camMorphoMaths(&source,&dest,&mm_params);
    t2=camGetTimeMs();
		printf("time: %d\n", t2 -t1);
    camSavePGM(&dest, argv[2]);

	return 0;
}


